﻿using Soul.Request;
using System.ServiceModel;

namespace Soul.Command
{
    class CommandRequestHandler : IRequestHandler
    {
        private CommandFactory factory;

        public CommandRequestHandler(CommandFactory factory)
        {
            this.factory = factory;
        }

        #region IRequestHandler 成员

        public bool CanProcess(RequestContext context)
        {
            return context is CommandRequestContext;
        }

        public void ProcessRequest(RequestContext requestContext)
        {
            //if (this.CanProcess(requestContext))
            {
                var callback = OperationContext.Current.GetCallbackChannel<IRequestCallback>();
                callback.ExecuteCallback(null);
                //var context = requestContext as CommandRequestContext;
                //var command = this.factory.TryCreate(context.CommandArgument);
                //if (command != null)
                //{
                //    var result = command.Execute(context.CommandArgument);
                //    var callback = OperationContext.Current.GetCallbackChannel<IRequestCallback>();
                //    callback.ExecuteCallback(result);
                //}
            }
        }

        #endregion
    }
}
